package com.atguigu.tingshu.order.receiver;

import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.order.service.OrderInfoService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * @author atguigu-mqx
 * @ClassName OrderReceiver
 * @description: TODO
 * @date 2024年01月08日
 * @version: 1.0
 */
@Component
public class OrderReceiver {

    @Autowired
    private OrderInfoService orderInfoService;

    /**
     * 监听订单支付成功消息。
     * @param record
     */
    @KafkaListener(topics = KafkaConstant.QUEUE_ORDER_PAY_SUCCESS)
    public void orderPaySuccess(ConsumerRecord<String,String> record){
        //  获取到发送消息.
        String orderNo = record.value();
        //  判断
        if (!StringUtils.isEmpty(orderNo)){
            //  调用服务层方法.
            orderInfoService.orderPaySuccess(orderNo);
        }
    }
}
